package com.googlecode.allinclusive.tools.srcgen;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.googlecode.allinclusive.fw.core.springframework.utils.SpringUtils;
import com.googlecode.allinclusive.tools.srcgen.database.DatabaseIntrospector;
import com.googlecode.allinclusive.tools.srcgen.database.TableDefinition;
import com.googlecode.allinclusive.tools.srcgen.generator.Generator;

/**
 * Source Generator
 */
public class SourceGenerator {

	private static final Log log = LogFactory.getLog(SourceGenerator.class);
	
	private List<Generator> generators;
	
	private DatabaseIntrospector introspector;
	
	private String catalog;
	
	private String schema;
	
	public void generate() {
		log.debug("generate start...");
		List<TableDefinition> tableDefinitions = introspector.introspectTables(catalog, schema);
		for (Generator g : generators) {
			g.generate(tableDefinitions);
		}
		log.debug("generate end...");
	}
	
	public void setGenerators(List<Generator> generators) {
		this.generators = generators;
	}

	public void setIntrospector(DatabaseIntrospector introspector) {
		this.introspector = introspector;
	}

	public void setCatalog(String catalog) {
		this.catalog = catalog;
	}

	public void setSchema(String schema) {
		this.schema = schema;
	}
	
	public static void main(String[] args) {
		SourceGenerator sg = SpringUtils.getBean(SourceGenerator.class);
		sg.generate();
	}
}
